﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace QuanLyDuocPham.Controllers.UC.QuanLyCauHinh.NguoiDung
{
    /// <summary>
    /// Interaction logic for UC_NHOMND_List.xaml
    /// </summary>
    public partial class UC_NHOMND_List : UserControl, IDisposable
    {
        public void Dispose()
        {
            if (nhomndctrl != null)
            {
                nhomndctrl.Dispose();
                nhomndctrl = null;
            }
        }
        public UC_NHOMND_List()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            loadNHOMND();
        }
        Controllers.QuanLyCauHinh.NguoiDung.NHOMND_Control nhomndctrl = new Controllers.QuanLyCauHinh.NguoiDung.NHOMND_Control();
        private void loadNHOMND()
        {
            nhomndctrl.loadData(lvNHOMND_List);
        }
        
        private void btnAddNHOMND_Click(object sender, RoutedEventArgs e)
        {
            View.QuanLyCauHinh.NguoiDung.NHOMND_Add_View addnhomnd = new View.QuanLyCauHinh.NguoiDung.NHOMND_Add_View();
            addnhomnd.done = new View.QuanLyCauHinh.NguoiDung.NHOMND_Add_View.added(loadNHOMND);
            addnhomnd.ShowDialog();
        }

        private void btnEditNHOMND_Click(object sender, RoutedEventArgs e)
        {
            if (lvNHOMND_List.SelectedItem == null)
            {
                MessageBox.Show("Vui lòng chọn nhóm cần sửa!");
            }
            else
            {
                QuanLyDuocPham.View.QuanLyCauHinh.NguoiDung.NHOMND_Edit_View editnhomnd = new QuanLyDuocPham.View.QuanLyCauHinh.NguoiDung.NHOMND_Edit_View();
                var a = (NHOMND_Get_ListResult)lvNHOMND_List.SelectedItem;
                editnhomnd._ma_nhom_nd= a.MA_NHOMND;
                editnhomnd.done = new View.QuanLyCauHinh.NguoiDung.NHOMND_Edit_View.added(loadNHOMND);
                editnhomnd.ShowDialog();
            }
        }

        private void btnDeleteNHOMND_Click(object sender, RoutedEventArgs e)
        {
            if (lvNHOMND_List.SelectedItem == null)
            {
                MessageBox.Show("Vui lòng chọn nhóm cần xóa!");
            }
            else
            {
                var a = (NHOMND_Get_ListResult)lvNHOMND_List.SelectedItem;

                if (MessageBox.Show("Bạn có chắc chắn muốn xóa " + a.DIEN_GIAI, "Cảnh báo", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    string error = "";
                    error = nhomndctrl.deleteData(a.MA_NHOMND, error);
                    MessageBox.Show(error);
                }
            }
        }

    }
}
